C++ fopen() 您所在的位置:网站首页 file *fp=fopen C++ fopen()

C++ fopen()

#C++ fopen()| 来源: 网络整理| 查看: 265

fopen() prototype FILE* fopen (const char* filename, const char* mode);

The fopen() function takes a two arguments and returns a file stream associated with that file specified by the argument filename.

It is defined in header file.

Different types of file access mode are as follows:

File Access Mode Interpretation If file exists If file doesn't exist "r" Opens the file in read mode Read from start Error "w" Opens the file in write mode Erase all the contents Create new file "a" Opens the file in append mode Start writing from the end Create new file "r+" Opens the file in read and write mode Read from start Error "w+" Opens the file in read and write mode Erase all the contents Create new file "a+" Opens the file in read and write mode Start writing from the end Create new file fopen() Parameters filename: Pointer to the string containing the name of the file to be opened. mode: Pointer to the string that specifies the mode in which file is opened. fopen() Return value If successful, the fopen() function returns a pointer to the FILE object that controls the opened file stream. On failure, it returns a null pointer. Example 1: Opening a file in write mode using fopen() #include #include using namespace std; int main() { int c; FILE *fp; fp = fopen("file.txt", "w"); char str[20] = "Hello World!"; if (fp) { for(int i=0; i


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

      专题文章
        CopyRight 2018-2019 实验室设备网 版权所有